import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
// const Login = () => import(/* webpackChunkName: "group-login" */ '../components/Login.vue')
import Home from '../components/home.vue'
// const Home = () => import(/* webpackChunkName: "group-home" */ '../components/home.vue')
import Welcome from '../components/welcome.vue'
// const Welcome = () => import(/* webpackChunkName: "group-welcom" */ '../components/welcome.vue')
import Users from '../components/users.vue'
// const Users = () => import(/* webpackChunkName: "group-user" */ '../components/users.vue')
import Rights from '../components/rights.vue'
// const Rights = () => import(/* webpackChunkName: "group-3" */ '../components/rights.vue')
import Roles from '../components/roles.vue'
// const Roles = () => import(/* webpackChunkName: "group-3" */ '../components/roles.vue')
import Params from '../components/params.vue'
// const Params = () => import(/* webpackChunkName: "group-4" */ '../components/params.vue')
import Reports from '../components/reports.vue'
// const Reports = () => import(/* webpackChunkName: "group-5" */ '../components/reports.vue')
import Orders from '../components/orders.vue'
// const Orders = () => import(/* webpackChunkName: "group-6" */ '../components/orders.vue')
import Goods from '../components/goods.vue'
// const Goods = () => import(/* webpackChunkName: "group-7" */ '../components/goods.vue')
import Categories from '../components/categories.vue'
// const Categories = () => import(/* webpackChunkName: "group-7" */ '../components/categories.vue')
import Addgoods from '../components/goods_add.vue'
// const Addgoods = () => import(/* webpackChunkName: "group-7" */ '../components/goods_add.vue')
Vue.use(VueRouter)

const routes = [{ path: '/Login', component: Login }, { path: '/', redirect: '/Login' },
{ path: '/Home', component: Home ,redirect:"/Welcome" ,children:[
  {path:"/Welcome",component:Welcome},
  {path:"/users",component:Users},
  {path:"/rights",component:Rights},
  {path:"/roles",component:Roles},
  {path:"/params",component:Params},
  {path:"/reports",component:Reports},
  {path:"/orders",component:Orders},
  {path:"/goods",component:Goods},
  {path:"/categories",component:Categories},
  {path:"/goods_add",component:Addgoods},
]}]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  //to 将要访问的路径
  //from 从哪个路径跳转而来
  //next 是一个函数，表示放行 next('/Login')
  if (to.path == '/Login') return next();
  const token = window.sessionStorage.getItem('token');
  if (!token) return next("/Login");
  next();
})
export default router
